/*
 * Conexion.java
 *
 * Created on 8 de junio de 2004, 20:20
 * 
			//jdbc driver para MySql	
			Class.forName ("com.mysql.jdbc.Driver");
		    String URL = "jdbc:mysql://127.0.0.1:3306/vbscript";
		    
			//bridge jdbc:odbc - Driver de Sun
			Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
			String URL = "jdbc:odbc:DSN";
		
			//jdbc driver para MS SQL Server 2000        
			Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
			String URL = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs";
		
			//jdbc driver para Sybase Adaptive Server
			Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
			String URL = "jdbc:sybase:Tds:servidor:1234/database?";
		
			//jdbc driver para PostgreSQL
			Class.forName("org.postgresql.Driver");
			String URL= "jdbc:postgresql://localhost:5432/PRUEBA";
 */

package jdbc_01;

public class Conexion {
    
    private String dsn, usu, pwd;
    private java.sql.Connection con;
    private static final String ODBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
    
    public Conexion(String dsn, String usu, String pwd) { 
        this.dsn = dsn;
        this.usu = usu;
        this.pwd = pwd;
    }
    
    public java.sql.Connection getCon() { return con; }
    
    public boolean abrirConexion() {
        String url = "jdbc:odbc:".concat(dsn);
        try {
            con = java.sql.DriverManager.getConnection(url,usu,pwd);
            return true;
        } catch( java.sql.SQLException e ) { 
            return false;
        }
    }
    
    public boolean cerrarConexion() {
        try {
            con.close();
            return true;
        } catch( java.sql.SQLException e ) { 
            return false;
        }
    }
    
    public static void driverOdbc() {
        try {
            Class.forName(ODBC_DRIVER);
        } catch( ClassNotFoundException e ) { }
    }    
}